package org.abettor.angleworm;

import org.abettor.angleworm.auth.AccountType;
import org.abettor.angleworm.i18n.Translator;
import org.abettor.angleworm.ui.AccountTypeDialog;
import org.abettor.angleworm.ui.AgreementDialog;
import org.abettor.angleworm.ui.LanguageSwitchDialog;
import org.abettor.angleworm.util.Configuration;

/**
 * 入口方法类
 * @author shawn
 *
 */
public class Angleworm
{
	public static void main(String[] args) throws Exception
	{
		//	获取默认语言
		String language = Configuration.getDefaultLanguage();
		Translator.initialize(language);

		//	如果没有设定默认语言，让用户选择一个
		if(language == null || language.isEmpty())
		{
			LanguageSwitchDialog languageSwitch = new LanguageSwitchDialog();
			languageSwitch.show();
			language = languageSwitch.getLanguage();
			if(language != null && ! language.isEmpty())
			{
				Translator trans = Translator.getInstance();
				trans.switchToLanguage(language);
				Configuration.setDefaultLanguage(language);
				Configuration.save();
			}
		}

		//	显示声明条款对话框
		boolean agree = Configuration.isAgreementConfirmed();
		if(! agree)
		{
			AgreementDialog agreement = new AgreementDialog();
			agreement.show();
			if(! agreement.isAgreed())
			{
				return;
			}

			Configuration.confirmAgreement();
			Configuration.save();
		}

		//	显示登录帐号类型窗口
		AccountType accountType = Configuration.getDefaultAccountType();
		if(accountType == null)
		{
			AccountTypeDialog accountTypeDialog = new AccountTypeDialog();
			accountTypeDialog.show();
			accountType = accountTypeDialog.getAccountType();
		}

		if(accountType == null)
		{
			return;
		}
		System.out.println(accountType.name());
	}
}
